import Vue from 'vue'
import App from './App.vue'
import Storage from 'vue-ls'
import router from './router'
import store from './store/'

import { VueAxios } from "@/utils/request"

import Antd from 'ant-design-vue'
import Viser from 'viser-vue'
import 'ant-design-vue/dist/antd.less';  // or 'ant-design-vue/dist/antd.less'

import '@/permission' // permission control
import '@/utils/filter' // base filter
import Print from 'vue-print-nb-jeecg'
/*import '@babel/polyfill'*/
import VueApexCharts from 'vue-apexcharts'

import preview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'
import "@jeecg/antd-onine"
import '@jeecg/antd-onine/dist/OnlineForm.css'

import VueI18n from 'vue-i18n'
import LangENUS from '@/assets/lang/en-us'
import LangZHCN from '@/assets/lang/zh-cn'
import LangVIVN from '@/assets/lang/vi-vn'


import {
  ACCESS_TOKEN,
  DEFAULT_COLOR,
  DEFAULT_THEME,
  DEFAULT_LAYOUT_MODE,
  DEFAULT_COLOR_WEAK,
  SIDEBAR_TYPE,
  DEFAULT_FIXED_HEADER,
  DEFAULT_FIXED_HEADER_HIDDEN,
  DEFAULT_FIXED_SIDEMENU,
  DEFAULT_CONTENT_WIDTH_TYPE,
  DEFAULT_MULTI_PAGE
} from "@/store/mutation-types"
import config from '@/defaultSettings'

import JDictSelectTag from './components/dict/index.js'
import hasPermission from '@/utils/hasPermission'
import vueBus from '@/utils/vueBus';
import JeecgComponents from '@/components/jeecg/index'
import Cookies from 'js-cookie'
import moment from 'moment'
import 'moment/locale/zh-cn'
const langCookieKey = 'lang'
const EN = 'en-us'
const ZH = 'zh-cn'
const VN = 'vi-vn'
Vue.config.productionTip = false
Vue.use(Storage, config.storageOptions)
Vue.use(Antd)
Vue.use(VueAxios, router)
Vue.use(Viser)
Vue.use(hasPermission)
Vue.use(JDictSelectTag)
Vue.use(Print)
Vue.use(VueApexCharts)
Vue.component('apexchart', VueApexCharts)
Vue.use(preview)
Vue.use(vueBus);
Vue.use(JeecgComponents);


Vue.use(VueI18n)
let l = 'zh-cn'
if (Cookies.get(langCookieKey)) {
  let lang = Cookies.get(langCookieKey)
  if (lang != null && lang === EN) {
     l = 'en-us'
  } else if(lang != null && lang === EN){
    l = 'vi-vn'
  }
  
}

const i18n = new VueI18n({
  locale: l,
  messages: {
    'en-us': LangENUS,
    'zh-cn': LangZHCN,
    'vi-vn': LangVIVN
  }
})

new Vue({
  router,
  store,
  i18n,
  mounted () {
    store.commit('SET_SIDEBAR_TYPE', Vue.ls.get(SIDEBAR_TYPE, true))
    store.commit('TOGGLE_THEME', Vue.ls.get(DEFAULT_THEME, config.navTheme))
    store.commit('TOGGLE_LAYOUT_MODE', Vue.ls.get(DEFAULT_LAYOUT_MODE, config.layout))
    store.commit('TOGGLE_FIXED_HEADER', Vue.ls.get(DEFAULT_FIXED_HEADER, config.fixedHeader))
    store.commit('TOGGLE_FIXED_SIDERBAR', Vue.ls.get(DEFAULT_FIXED_SIDEMENU, config.fixSiderbar))
    store.commit('TOGGLE_CONTENT_WIDTH', Vue.ls.get(DEFAULT_CONTENT_WIDTH_TYPE, config.contentWidth))
    store.commit('TOGGLE_FIXED_HEADER_HIDDEN', Vue.ls.get(DEFAULT_FIXED_HEADER_HIDDEN, config.autoHideHeader))
    store.commit('TOGGLE_WEAK', Vue.ls.get(DEFAULT_COLOR_WEAK, config.colorWeak))
    store.commit('TOGGLE_COLOR', Vue.ls.get(DEFAULT_COLOR, config.primaryColor))
    store.commit('SET_TOKEN', Vue.ls.get(ACCESS_TOKEN))
    store.commit('SET_MULTI_PAGE',Vue.ls.get(DEFAULT_MULTI_PAGE,true))
  },
  created () {
    let lang = ZH;
    if (Cookies.get(langCookieKey)) {
        lang = Cookies.get(langCookieKey) 
    }
    if (lang != null && lang === ZH) {
        this.isZHCN = true
        this.$i18n.locale = ZH
        moment.locale(ZH)
    } else if (lang != null && lang === VN) {
      this.isZHCN = false
      this.$i18n.locale = VN
        moment.locale(VN)
    } else {
      this.isZHCN = false
      this.$i18n.locale = EN
        moment.locale(EN)
    }
    store.commit('SET_LANG', lang)
  },
  methods: {
    moment,
  },
  render: h => h(App)
}).$mount('#app')
